home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / uucp106d / part06 < prev    next >
Encoding:
Internet Message Format  |  1990-06-28  |  57.1 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i184: UUCP 1.06D - UNIX compatible uucp/news/mail system, Part06/12
  5. Message-ID: <12975@xanth.cs.odu.edu>
  6. Date: 28 Jun 90 12:22:52 GMT
  7. Sender: news@cs.odu.edu
  8. Reply-To: Matt Dillon <@uunet.uu.net:overload!dillon>
  9. Lines: 2777
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: Matt Dillon <@uunet.uu.net:overload!dillon>
  15. Posting-number: Volume 90, Issue 184
  16. Archive-name: unix/uucp-1.06d/part06
  17.  
  18. #!/bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 6 (of 12)."
  25. # Contents:  uucp2/src/anews/showart.c uucp2/src/dmail/commands.c
  26. #   uucp2/src/dmail/sendmail.c uucp2/src/unix/dcron.c
  27. #   uucp2/src/uucico/sysdep.c
  28. # Wrapped by tadguy@xanth on Thu Jun 28 08:21:27 1990
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'uucp2/src/anews/showart.c' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'uucp2/src/anews/showart.c'\"
  32. else
  33. echo shar: Extracting \"'uucp2/src/anews/showart.c'\" \(8978 characters\)
  34. sed "s/^X//" >'uucp2/src/anews/showart.c' <<'END_OF_FILE'
  35. X
  36. X/*
  37. X *  SHOWART.C
  38. X */
  39. X
  40. X#include "news.h"
  41. X#include <ctype.h>
  42. X
  43. X#define ON        scr_inverse_on()
  44. X#define OFF        scr_inverse_off()
  45. X#define Clear_Line    printf("\r\x9bK")
  46. X#define Clear_Screen    printf("\x9bH\x9bJ")
  47. X
  48. Xextern void scr_inverse_on(), scr_inverse_off();
  49. Xextern void do_help();
  50. Xextern char *get_next_art();
  51. Xextern char *subs();
  52. Xextern char *art2file();
  53. X
  54. Xextern char *NewsDir;
  55. X
  56. Xstatic char *ArtHelp[] = {
  57. X    "(space)     Display next page of current article",
  58. X    "(return)    Display next line of current article (scroll)",
  59. X    "(backspace) Restart current article",
  60. X    "n/N         Goto the next article",
  61. X    "d/D         Delete this article",
  62. X    "u/U         Undelete this article",
  63. X    "-           Backup to previous article",
  64. X    "^           Goto the first article",
  65. X    "(number)    Goto the given article number",
  66. X    "$           Goto next news group",
  67. X    "r/R         Reply -- send mail to the poster of current article",
  68. X    "f/F         Followup -- post a response to the current article",
  69. X    "p/P         Post  -- post an article",
  70. X    "=           List article subjects for the remaining articles",
  71. X    "./>         Scan subject of next article, hit return to read it",
  72. X    ",/<         Backup one article, displaying its subject",
  73. X    "s/S         Write the current article to a file",
  74. X    "w/W         Write the current article to a file",
  75. X    "h/H/?       Display help",
  76. X    "q           Quit newsgroup (qq = quit program)",
  77. X    "Q           Quit newsgroup without deleting any articles",
  78. X    0
  79. X};
  80. X
  81. Xstatic char *suppressed[] = {
  82. X    "Path",
  83. X    "Message-ID",
  84. X    "Message-Id",
  85. X    "Lines",
  86. X    "Xref",
  87. X    "References",
  88. X    "Nf-From",
  89. X    "Nf-ID",
  90. X    "In-reply-to",
  91. X    "From ",
  92. X    "Received",
  93. X    0
  94. X};
  95. X
  96. Xstatic int
  97. Xshowheader(register char *p)
  98. X{
  99. X    register char **pp;
  100. X
  101. X    for (pp = suppressed; *pp != NULL; pp++) {
  102. X    if (strcmp(*pp, p) == 0)
  103. X        return (0);
  104. X    }
  105. X    return (1);
  106. X}
  107. X
  108. Xstatic int EndOfFile, LineCount, CharCount;
  109. Xstatic int LineMax, CharMax;
  110. Xstatic long LastLine;
  111. X
  112. Xstatic void
  113. XSetupPage(void)
  114. X{
  115. X    Clear_Screen;
  116. X    LineCount = 1, CharCount = 1;
  117. X/* FIXME: determine size of page dynamically */
  118. X    LineMax = NumRows;
  119. X    CharMax = NumCols;
  120. X    raw(stdin);     /* permit typeahead while displaying page */
  121. X}
  122. X
  123. Xstatic int
  124. Xoutc(register int c)
  125. X{
  126. X    if (c == '\t') {
  127. X    switch(CharCount%8) {
  128. X    case 1: outc(' ');
  129. X    case 2: outc(' ');
  130. X    case 3: outc(' ');
  131. X    case 4: outc(' ');
  132. X    case 5: outc(' ');
  133. X    case 6: outc(' ');
  134. X    case 7: outc(' ');
  135. X    case 0: outc(' ');
  136. X    }
  137. X    return 0;
  138. X    }
  139. X    if (c == '\f') {
  140. X    LineCount = 999;
  141. X    c = '\n';
  142. X    }
  143. X    if (CharCount > CharMax) {
  144. X    ++LineCount;
  145. X    CharCount = 1;
  146. X    if (c == '\n')
  147. X        return (1);
  148. X    }
  149. X    putchar(c);
  150. X    ++CharCount;
  151. X    if (c == '\n') {
  152. X    ++LineCount, CharCount = 1;
  153. X    return (1);
  154. X    }
  155. X    return (0);
  156. X}
  157. X
  158. Xstatic void
  159. Xputline(register char *prefix, register FILE *fp)
  160. X{
  161. X    register int c;
  162. X
  163. X    EndOfFile = 0;
  164. X
  165. X    LastLine = ftell(fp);   /* remember where this line started */
  166. X
  167. X    while (*prefix != '\0') {
  168. X    if (outc(*prefix))
  169. X        return;
  170. X    ++prefix;
  171. X    }
  172. X    while ((c = getc(fp)) != EOF) {
  173. X    if (outc(c)) {
  174. X        if (c == '\f') {
  175. X        /* force page break after form feed */
  176. X        LastLine = ftell(fp);
  177. X        }
  178. X        if ((c = getc(fp)) == EOF)
  179. X        break;
  180. X        ungetc(c, fp);
  181. X        return;
  182. X    }
  183. X    }
  184. X    /* End-of-file */
  185. X    EndOfFile = 1;
  186. X    mark_cur_art(1);
  187. X    LineCount = 999;
  188. X}
  189. X
  190. Xstatic int
  191. XDisplayHdr(register FILE *fp)
  192. X{
  193. X    register char *p;
  194. X    register int c, result = 0;
  195. X    long here;
  196. X    char buf[100];
  197. X
  198. X    for (;;) {
  199. X    /* Evaluate one header line */
  200. X    here = ftell(fp);
  201. X    p = buf;
  202. X
  203. X    do {    /* extract command portion */
  204. X        if ((c = getc(fp)) == EOF)
  205. X        return result;
  206. X        if (c == '\n') {
  207. X        fseek(fp, here, 0);
  208. X        return result;
  209. X        }
  210. X        *p++ = c;
  211. X        if (c == ' ') {
  212. X        ++p;
  213. X        break;
  214. X        }
  215. X    } while (c != ':');
  216. X    *--p = '\0';
  217. X
  218. X    if ((c = getc(fp)) != ' ')      /* ignore space after colon */
  219. X        ungetc(c, fp);
  220. X
  221. X    /* check for special action on header line */
  222. X    if (strcmp(buf, "Subject") == 0) {
  223. X        ON;
  224. X        putline("", fp);
  225. X        OFF;
  226. X    } else if (strcmp(buf, "Control") == 0) {
  227. X        ON;
  228. X        putline("Control: ", fp);
  229. X        OFF;
  230. X        result = 1;
  231. X    } else if (showheader(buf)) {
  232. X        *p++ = ':';
  233. X        *p++ = ' ';
  234. X        *p = '\0';
  235. X        putline(buf, fp);
  236. X    } else {
  237. X        /* ignore skipped header, including continuations */
  238. X
  239. X        do {
  240. X        while ((c = getc(fp)) != '\n') {
  241. X            if (c == EOF)
  242. X            return result;
  243. X        }
  244. X        } while ((c = getc(fp)) == '\t' || c == ' ');
  245. X
  246. X        if (c == EOF)
  247. X        return result;
  248. X        ungetc(c, fp);
  249. X    }
  250. X
  251. X    while ((c = getc(fp)) != EOF) {
  252. X        if (c == '\n') {        /* end of headers */
  253. X        ungetc(c, fp);
  254. X        return result;
  255. X        }
  256. X        if (c != '\t' && c != ' ')
  257. X        break;
  258. X
  259. X        /* continuation lines */
  260. X        do {
  261. X        outc(c);
  262. X        if ((c = getc(fp)) == EOF)
  263. X            return result;
  264. X        } while (c != '\n');
  265. X
  266. X        outc(c);
  267. X    }
  268. X    ungetc(c, fp);
  269. X    }
  270. X}
  271. X
  272. Xstatic void    /* minimize swapping if copying on floppies */
  273. Xcopyfile(register FILE *in, char *new)
  274. X{
  275. X    register char *bp;
  276. X    register long size = 16*1024;
  277. X    register FILE *out;
  278. X    register long i;
  279. X    int append = 0;
  280. X    extern void *malloc();
  281. X
  282. X    if (!*new)
  283. X    return;
  284. X    if (access(new, 0) == 0) {
  285. X    if ((out = fopen(new, "a")) == NULL) {
  286. X        printf("could not open %s for append\n", new);
  287. X        return;
  288. X    }
  289. X    append = 1;
  290. X    } else if ((out = fopen(new, "w")) == NULL) {
  291. X    printf("could not open %s for output\n", new);
  292. X    return;
  293. X    }
  294. X    while ((bp = malloc(size)) == NULL) {
  295. X    if ((size = size/2) < 1024) {
  296. X        printf("NO MEMORY TO MAKE COPY!\n");
  297. X        fclose(out);
  298. X        return;
  299. X    }
  300. X    }
  301. X    rewind(in);
  302. X    while ((i = fread(bp, sizeof(char), size, in)) > 0)
  303. X    fwrite(bp, sizeof(char), i, out);
  304. X    fclose(out); free(bp);
  305. X    printf("Article %sed to %s\n", append ? "append" : "sav", new);
  306. X}
  307. X
  308. Xstatic void    /* sends subject via outc() with format "%4s:%s\n" */
  309. Xoutsub(char *s, char *t)
  310. X{
  311. X    register int i = 4 - strlen(s);
  312. X
  313. X    while (i > 0)
  314. X    outc(' '), --i;
  315. X    while (*s != '\0')
  316. X    outc(*s++);
  317. X    outc(':');
  318. X    while (*t != '\0')
  319. X    outc(*t++);
  320. X    outc('\n');
  321. X}
  322. X
  323. Xvoid
  324. XNextArtPage(char *article, char *group)
  325. X{
  326. X    SetupPage();
  327. X    ON;
  328. X    printf("Article %s of %s (%d unread)", article, group, unread_count());
  329. X    OFF;
  330. X    outc('\n');
  331. X}
  332. X
  333. Xvoid
  334. Xscan_subjects(char *group)
  335. X{
  336. X    register char *ptr, *s;
  337. X    register int ch;
  338. X
  339. X    SetupPage();
  340. X    while (ptr = get_next_art()) {
  341. X    if (LineCount >= LineMax) {
  342. X        ON;
  343. X        printf("(Hit any key to continue)");
  344. X        OFF;
  345. X        ch = rawch();
  346. X        Clear_Line;
  347. X        if (ch == 'q')
  348. X            break;
  349. X        SetupPage();
  350. X    }
  351. X    if ((s = subs(art2file(group, ptr))) != NULL)
  352. X        outsub(ptr, s);
  353. X    else
  354. X        outsub(ptr, "(((No Subject Line Found!!!)))");
  355. X    }
  356. X}
  357. X
  358. Xint
  359. Xshowart(char *group, char *article)
  360. X{
  361. X    register FILE *fp;
  362. X    register int done, ch;
  363. X    char newname[100];
  364. X
  365. X    if ((fp = fopen(art2file(group, article), "r")) == NULL) {
  366. X    printf("Error opening article %s in group %s\n", article, group);
  367. X    ON;
  368. X    printf("(Hit any key to continue)");
  369. X    OFF;
  370. X    rawch();
  371. X    Clear_Line;        /* Erase the prompt */
  372. X    fflush(stdout);
  373. X    return 'n';
  374. X    }
  375. X
  376. X    /* display initial page with headers */
  377. X    DisplayArt:
  378. X
  379. X    NextArtPage(article, group);
  380. X    done = DisplayHdr(fp);
  381. X    while (LineCount < LineMax)
  382. X    putline("", fp);
  383. X
  384. X    ch = 'd';
  385. X    while (done == 0) {
  386. X    ON;
  387. X    printf((EndOfFile) ? "===== End of article =====" : "--- More ---");
  388. X    OFF;
  389. X    putchar(' ');
  390. X    ch = rawch();
  391. X
  392. X    Clear_Line;        /* Erase the prompt */
  393. X    fflush(stdout);
  394. X
  395. X    switch (ch) {
  396. X    case ' ':
  397. X        if (EndOfFile) {
  398. X        done = 1;
  399. X        ch = 'd';
  400. X        break;
  401. X        }
  402. X        /* fall through to... */
  403. X    case '\t':
  404. X        fseek(fp, LastLine, 0);
  405. X        NextArtPage(article, group);
  406. X        while (LineCount < LineMax)
  407. X        putline("", fp);
  408. X        break;
  409. X
  410. X    case '\n':
  411. X    case '\r':
  412. X        putline("", fp);
  413. X        break;
  414. X
  415. X    case '\b':
  416. X        rewind(fp);
  417. X        goto DisplayArt;
  418. X
  419. X    case 'f':
  420. X    case 'F':
  421. X        followup(ch, fp, group);
  422. X        break;
  423. X
  424. X    case 'r':
  425. X    case 'R':
  426. X        reply(ch, fp, group);
  427. X        break;
  428. X
  429. X    case 'p':
  430. X    case 'P':
  431. X        followup(ch, NULL, group);
  432. X        break;
  433. X
  434. X    case '?':
  435. X    case 'h':
  436. X    case 'H':
  437. X        ON;
  438. X        printf("%s [%s]?", group, article);
  439. X        OFF;
  440. X        do_help(ArtHelp);
  441. X        break;
  442. X
  443. X    case 'w':
  444. X    case 'W':
  445. X    case 's':
  446. X    case 'S':
  447. X        ON;
  448. X        printf("Save article %s as ??", article);
  449. X        OFF;
  450. X        putchar(' ');
  451. X        fflush(stdout);
  452. X        gets(newname);
  453. X        copyfile(fp, newname);
  454. X        break;
  455. X
  456. X    case '=':
  457. X        scan_subjects(group);
  458. X        break;
  459. X
  460. X    case 'u':
  461. X    case 'U':
  462. X        del_cur_art(0);
  463. X        break;
  464. X
  465. X        /* move to another article */
  466. X    case '-':               /* previous article */
  467. X    case '$':               /* next news group */
  468. X    case '0': case '1': case '2': case '3': case '4':
  469. X    case '5': case '6': case '7': case '8': case '9':
  470. X    case '.': case '>': case ',': case '<':
  471. X        hold_cur_art();
  472. X        /* fall through to... */
  473. X        /* these cases are handled by the group-level processing */
  474. X    case 'd': case 'D':     /* delete article */
  475. X    case 'n': case 'N':     /* to next article */
  476. X    case 'q': case 'Q':     /* quit news */
  477. X    case '^':               /* first article */
  478. X        done = 1;
  479. X        /* fall through to... */
  480. X    default:
  481. X        break;
  482. X    }
  483. X    }
  484. X
  485. X    fclose(fp);
  486. X    return (ch);
  487. X}
  488. X
  489. END_OF_FILE
  490. if test 8978 -ne `wc -c <'uucp2/src/anews/showart.c'`; then
  491.     echo shar: \"'uucp2/src/anews/showart.c'\" unpacked with wrong size!
  492. fi
  493. # end of 'uucp2/src/anews/showart.c'
  494. fi
  495. if test -f 'uucp2/src/dmail/commands.c' -a "${1}" != "-c" ; then 
  496.   echo shar: Will not clobber existing file \"'uucp2/src/dmail/commands.c'\"
  497. else
  498. echo shar: Extracting \"'uucp2/src/dmail/commands.c'\" \(10526 characters\)
  499. sed "s/^X//" >'uucp2/src/dmail/commands.c' <<'END_OF_FILE'
  500. X
  501. X/*
  502. X * COMMANDS.C
  503. X *
  504. X *  $Header: Beta:src/uucp/src/dmail/RCS/commands.c,v 1.1 90/02/02 12:04:08 dillon Exp Locker: dillon $
  505. X *
  506. X *  (C) Copyright 1985-1990 by Matthew Dillon,  All Rights Reserved.
  507. X *
  508. X *  Global Routines:    DO_QUIT()
  509. X *            DO_EXIT()
  510. X *            DO_CD()
  511. X *            DO_ECHO()
  512. X *            DO_GO()
  513. X *            DO_SOURCE()
  514. X *            DO_SHELL()
  515. X *            DO_WRITE()
  516. X *            DO_DELNEXT()
  517. X *            DO_NUMBER()
  518. X *            DO_NEXT()
  519. X *            DO_HEADER()
  520. X *            DO_TYPE()
  521. X *            DO_DELETE()
  522. X *            DO_UNDELETE()
  523. X *            DO_MARK()
  524. X *        DO_BREAK()
  525. X *
  526. X *  Static Routines:    None.
  527. X *
  528. X */
  529. X
  530. X#include <stdio.h>
  531. X#include <sys/file.h>
  532. X#include "dmail.h"
  533. X
  534. X#define LAST_TYPE   0
  535. X#define LAST_HEADER 1
  536. X
  537. Xstatic int Last_operation;
  538. Xstatic int Last_deleted = -1;
  539. Xstatic char ScrBuf[1024];
  540. X
  541. Xvoid
  542. Xdo_quit(garbage, com)
  543. Xchar *garbage;
  544. X{
  545. X    int fd, r, back;
  546. X    char *str;
  547. X
  548. X    push_break();
  549. X    if (get_inode (mail_file) == get_inode (output_file)) {
  550. X    back = save_file (0, 0, ST_DELETED | ST_STORED);
  551. X    } else {
  552. X    r = write_file (output_file, O_CREAT, ST_READ, ST_DELETED | ST_STORED);
  553. X    if (r < 0) {
  554. X        printf ("Unable to write to %s\n", output_file);
  555. X        back = save_file (0, 0, ST_DELETED | ST_STORED);
  556. X    } else {
  557. X        back = save_file (0, 0, ST_READ | ST_DELETED | ST_STORED);
  558. X    }
  559. X    }
  560. X    if (back < 0)
  561. X    printf ("Unable to update %s\n", mail_file);
  562. X    if (back > 0)
  563. X    printf ("%d  kept in %s\n", back, mail_file);
  564. X    sleep (1);
  565. X
  566. X    /*
  567. X     *    update access time (UNIX, so shell does not report new mail)
  568. X     */
  569. X
  570. X    if ((fd = open (mail_file, O_RDONLY, 0)) >= 0) {
  571. X    read (fd, Buf, 1);
  572. X    close (fd);
  573. X    }
  574. X    if (!com)
  575. X    done (0);
  576. X    free_entry();
  577. X    if (av[1] == 0) {
  578. X    if (!Silence)
  579. X        puts ("NO FROM FILE SPECIFIED");
  580. X    av[1] = mail_file;
  581. X    av[2] = NULL;
  582. X    }
  583. X    Did_cd = 0;
  584. X    mail_file = realloc (mail_file, strlen(av[1]) + 1);
  585. X    strcpy (mail_file, av[1]);
  586. X    str = (av[2]) ? av[2] : mail_file;
  587. X    output_file = realloc (output_file, strlen(str) + 1);
  588. X    strcpy (output_file, str);
  589. X    initial_load_mail();
  590. X    m_select (Nulav, M_RESET);
  591. X    pop_break();
  592. X    if (!Silence)
  593. X    printf ("\nRF %-20s   WF %-20s\n", mail_file, output_file);
  594. X}
  595. X
  596. Xvoid
  597. Xdo_exit(garbage, com)
  598. Xchar *garbage;
  599. X{
  600. X    char *str;
  601. X
  602. X    if (!com)
  603. X    done (0);
  604. X    push_break();
  605. X    free_entry();
  606. X    if (av[1] == 0) {
  607. X    if (!Silence)
  608. X        puts ("NO FROM FILE SPECIFIED");
  609. X    av[1] = mail_file;
  610. X    av[2] = NULL;
  611. X    }
  612. X    mail_file = realloc (mail_file, strlen(av[1]) + 1);
  613. X    strcpy (mail_file, av[1]);
  614. X    str = (av[2]) ? av[2] : mail_file;
  615. X    output_file = realloc (output_file, strlen(str) + 1);
  616. X    strcpy (output_file, str);
  617. X    initial_load_mail();
  618. X    m_select (Nulav, M_RESET);
  619. X    pop_break();
  620. X    if (!Silence)
  621. X    printf ("\nRF %-20s   WF %-20s\n", mail_file, output_file);
  622. X}
  623. X
  624. X
  625. Xdo_cd()
  626. X{
  627. X    char *dir = (ac < 2) ? home_dir : av[1];
  628. X
  629. X    if (chdir(dir) < 0) {
  630. X    printf ("Cannot CD to %s\n", dir);
  631. X    return (-1);
  632. X    }
  633. X    ++Did_cd;
  634. X    return (1);
  635. X}
  636. X
  637. X
  638. Xdo_echo(str)
  639. Xchar *str;
  640. X{
  641. X    puts (next_word(str));
  642. X    fflush(stdout);
  643. X    return (1);
  644. X}
  645. X
  646. X
  647. Xdo_go()
  648. X{
  649. X    int i;
  650. X
  651. X    if (ac < 2) {
  652. X    puts ("go to which article?");
  653. X    }
  654. X    rewind_range (1);
  655. X    i = get_range();
  656. X    if (i < 0) {
  657. X    if (!Silence)
  658. X        printf ("Message #%d does not exist\n", i);
  659. X    return (-1);
  660. X    }
  661. X    if (i == 0) {
  662. X    if (!Silence)
  663. X        puts ("No Message");
  664. X    return (-1);
  665. X    }
  666. X    Current = indexof(i);
  667. X    return (1);
  668. X}
  669. X
  670. X
  671. Xdo_source(scratch, overide)
  672. Xchar *scratch;
  673. X{
  674. X    char *comline = malloc(1024);
  675. X    FILE *fi = NULL;
  676. X
  677. X    if (ac < 2) {
  678. X    puts ("No file argument to source");
  679. X    free(comline);
  680. X    return (-1);
  681. X    }
  682. X    if (push_base()) {
  683. X    push_break();
  684. X    pop_base();
  685. X    if (fi != NULL)
  686. X        fclose (fi);
  687. X    pop_break();
  688. X    free(comline);
  689. X    return (-1);
  690. X    }
  691. X    push_break();
  692. X    fi = fopen (av[1], "r");
  693. X    pop_break();
  694. X    if (fi == NULL) {
  695. X    if (!overide)
  696. X        printf ("Cannot open %s\n", av[1]);
  697. X    free(comline);
  698. X    return (-1);
  699. X    }
  700. X    while (fgets (comline, 1024, fi) != NULL) {
  701. X    comline[strlen(comline) - 1] = '\0';
  702. X    if (comline[0] != '#')
  703. X        exec_command (comline);
  704. X    }
  705. X    push_break();
  706. X    fclose (fi);
  707. X    fi = NULL;
  708. X    free(comline);
  709. X    pop_break();
  710. X    pop_base();
  711. X    return (1);
  712. X}
  713. X
  714. X
  715. Xdo_shell(str)
  716. Xchar *str;
  717. X{
  718. X#ifdef UNIX
  719. X    int pid, ret;
  720. X#endif
  721. X    char *shell, *ptr;
  722. X    char *args;
  723. X
  724. X#ifdef AMIGA
  725. X    shell = "";
  726. X#else
  727. X    shell = getenv("SHELL");
  728. X#endif
  729. X    if (shell == NULL)
  730. X    shell = "/bin/sh";
  731. X    ptr = shell + strlen(shell) - 1;
  732. X    while (ptr > shell && *ptr && *ptr != '/')
  733. X    --ptr;
  734. X    args = (strcmp(ptr, "/sh"))? "-fc" : "-c";
  735. X    push_break();
  736. X    str = next_word (str);
  737. X#ifdef UNIX
  738. X    if (strlen (str)) {
  739. X    if ((pid = vfork()) == 0) {
  740. X        execl (shell, shell, args, str, NULL);
  741. X        _exit (1);
  742. X    }
  743. X    } else {
  744. X    if ((pid = vfork()) == 0) {
  745. X        execl (shell, shell, NULL);
  746. X        _exit (1);
  747. X    }
  748. X    }
  749. X    while ((ret = wait(0)) > 0) {
  750. X    if (ret == pid)
  751. X        break;
  752. X    }
  753. X#endif
  754. X#ifdef AMIGA
  755. X    Execute(str, NULL, NULL);
  756. X#endif
  757. X    pop_break();
  758. X    return (1);
  759. X}
  760. X
  761. X
  762. Xdo_write()
  763. X{
  764. X    char *file;
  765. X    int r, count = 0;
  766. X    register int i, j;
  767. X
  768. X    if (ac < 2) {
  769. X    puts ("You must specify at least a file-name");
  770. X    return (-1);
  771. X    }
  772. X    file = av[1];
  773. X    rewind_range (2);
  774. X    push_break();
  775. X    while (i = get_range()) {
  776. X    j = indexof (i);
  777. X    if (j >= 0  &&  !(Entry[j].status & ST_DELETED)) {
  778. X        Entry[j].status |= ST_STORED | ST_SCR;
  779. X        ++count;
  780. X    }
  781. X    }
  782. X    r = write_file (file, O_CREAT, ST_SCR, 0);
  783. X    rewind_range (2);
  784. X    if (r > 0) {
  785. X    while (i = get_range()) {
  786. X        j = indexof (i);
  787. X        if (j >= 0)
  788. X        Entry[j].status &= ~ST_SCR;
  789. X    }
  790. X    if (!Silence)
  791. X        printf ("%d Items written\n", count);
  792. X    } else {
  793. X    while (i = get_range()) {
  794. X        j = indexof (i);
  795. X        if (j >= 0)
  796. X        Entry[j].status &= ~(ST_SCR | ST_STORED);
  797. X    }
  798. X    printf ("Could not write to file %s\n", file);
  799. X    }
  800. X    pop_break();
  801. X    return (1);
  802. X}
  803. X
  804. X/*
  805. X * DB, added 3 Oct 1988
  806. X */
  807. X
  808. Xdo_delprev()
  809. X{
  810. X    do_mark("", ST_DELETED);
  811. X    if (Current)
  812. X    return(do_next("", -1));
  813. X    return(-1);
  814. X}
  815. X
  816. Xdo_delnext()
  817. X{
  818. X    static int warning;
  819. X
  820. X    if (!warning  &&  Last_operation == LAST_HEADER) {
  821. X    ++warning;
  822. X    puts ("Note that the next command is displaying headers only at");
  823. X    puts ("this point.  (one-time warning, NOTHING deleted");
  824. X    return (-1);
  825. X    }
  826. X    if (do_mark("", ST_DELETED) > 0)
  827. X    return (do_next("", 1));
  828. X    return (-1);
  829. X}
  830. X
  831. X
  832. Xdo_number(str, com)
  833. Xchar *str;
  834. Xint com;
  835. X{
  836. X    int x;
  837. X
  838. X    x = indexof (atoi(str));
  839. X    if (x < 0) {
  840. X    puts ("Non existant message");
  841. X    return (-1);
  842. X    }
  843. X    Current = x;
  844. X    switch (Last_operation) {
  845. X    case LAST_TYPE:
  846. X    return (do_type());
  847. X    case LAST_HEADER:
  848. X    return (do_header());
  849. X    default:
  850. X    puts ("Internal Error NEXT");
  851. X    return (-1);
  852. X    }
  853. X}
  854. X
  855. X
  856. Xdo_next(str, com)
  857. Xchar *str;
  858. X{
  859. X    int ok;
  860. X
  861. X    push_break();
  862. X    if (com > 0) {
  863. X    if (++Current > Entries)
  864. X        Current = Entries;
  865. X    if (fix() < 0) {
  866. X        puts ("End of file");
  867. X        pop_break();
  868. X        return (-1);
  869. X    }
  870. X    --com;
  871. X    }
  872. X    if (com < 0) {
  873. X    ++com;
  874. X    ok = 0;
  875. X    while (--Current >= 0) {
  876. X        if (Entry[Current].no  &&  !(Entry[Current].status & ST_DELETED)) {
  877. X        ok = 1;
  878. X        break;
  879. X        }
  880. X    }
  881. X    if (!ok) {
  882. X        puts ("Start of file");
  883. X    Current = 0;
  884. X        fix();
  885. X        pop_break();
  886. X        return (-1);
  887. X    }
  888. X    }
  889. X    pop_break();
  890. X    if (!com) {
  891. X    switch (Last_operation) {
  892. X    case LAST_TYPE:
  893. X        return (do_type());
  894. X    case LAST_HEADER:
  895. X        return (do_header());
  896. X    }
  897. X    }
  898. X    return (1);
  899. X}
  900. X
  901. X
  902. Xdo_header()
  903. X{
  904. X    Last_operation = LAST_HEADER;
  905. X    if (push_base()) {
  906. X    push_break();
  907. X    pop_base();
  908. X    PAGER (-1);
  909. X    rewind(m_fi);
  910. X    fflush (stdout);
  911. X    pop_break();
  912. X    return (-1);
  913. X    }
  914. X    if (single_position() < 0)
  915. X    return (-1);
  916. X    if (Current < 0) {
  917. X    puts("Software error #commands.0");
  918. X    exit(1);
  919. X    }
  920. X    PAGER (0);
  921. X    sprintf (Puf, "MESSAGE HEADER #%d (%d) %s\n",
  922. X        Entry[Current].no,
  923. X        Current + 1,
  924. X        (Entry[Current].status & ST_DELETED) ? "  DELETED" : "");
  925. X    PAGER (Puf);
  926. X    sprintf (Puf, "From %s\n", Entry[Current].from);
  927. X    PAGER (Puf);
  928. X    while (fgets (ScrBuf, 1024, m_fi) != NULL) {
  929. X    FPAGER (ScrBuf);
  930. X    if (*ScrBuf == '\n') {
  931. X        PAGER (-1);
  932. X        pop_base();
  933. X        return (1);
  934. X    }
  935. X    }
  936. X    PAGER ("END OF FILE ENCOUNTERED");
  937. X    PAGER (-1);
  938. X    pop_base();
  939. X    return (-1);
  940. X}
  941. X
  942. Xdo_type()
  943. X{
  944. X    int i;
  945. X
  946. X    Last_operation = LAST_TYPE;
  947. X    if (push_base()) {
  948. X    push_break();
  949. X    pop_base();
  950. X    PAGER (-1);
  951. X    rewind(m_fi);
  952. X    fflush (stdout);
  953. X    pop_break();
  954. X    return (-1);
  955. X    }
  956. X    if (single_position() < 0)
  957. X    return (-1);
  958. X    if (Current < 0) {
  959. X    puts("Software Error #commands.1");
  960. X    exit(1);
  961. X    }
  962. X    if (skip_to_data (m_fi) < 0) {
  963. X    printf ("Cannot find data for message %d\n", Entry[Current].no);
  964. X    return (-1);
  965. X    }
  966. X    PAGER (0);
  967. X    sprintf (Puf, "MESSAGE TEXT #%d (%d) %s\n",
  968. X        Entry[Current].no,
  969. X        Current + 1,
  970. X        (Entry[Current].status & ST_DELETED) ? "  DELETED" : "");
  971. X    PAGER (Puf);
  972. X    for (i = 0; i < Listsize; ++i) {
  973. X    if (*Entry[Current].fields[header[i]]) {
  974. X        sprintf (Puf, "%-10s %s",
  975. X            Find[header[i]].search,
  976. X            Entry[Current].fields[header[i]]);
  977. X        PAGER (Puf);
  978. X    }
  979. X    }
  980. X    PAGER ("");
  981. X    while ((fgets (ScrBuf, 1024, m_fi) != NULL)  &&  strncmp (ScrBuf, "From ", 5))
  982. X    FPAGER (ScrBuf);
  983. X    Entry[Current].status |= ST_READ;
  984. X    PAGER (-1);
  985. X    pop_base();
  986. X    return (1);
  987. X}
  988. X
  989. X
  990. Xdo_mark(garbage, mask)
  991. Xchar *garbage;
  992. X{
  993. X    int count = 0;
  994. X    register int i, j;
  995. X
  996. X    rewind_range (1);
  997. X    push_break();
  998. X    while (i = get_range()) {
  999. X    j = indexof (i);
  1000. X    if (j >= 0) {
  1001. X        if (mask & ST_DELETED)
  1002. X        Last_deleted = j;
  1003. X        if ((Entry[j].status & mask) != mask) {
  1004. X        Entry[j].status |= mask;
  1005. X        if (Entry[j].status & ST_DELETED)
  1006. X            Entry[j].status &= ~(ST_STORED | ST_READ | ST_TAG);
  1007. X        ++count;
  1008. X        }
  1009. X    }
  1010. X    }
  1011. X    if (!Silence)
  1012. X    printf ("%d  Items\n", count);
  1013. X    pop_break();
  1014. X    return (1);
  1015. X}
  1016. X
  1017. X
  1018. Xdo_unmark(garbage, mask)
  1019. Xchar *garbage;
  1020. X{
  1021. X    int count = 0;
  1022. X    register int i, j;
  1023. X    register struct ENTRY *en;
  1024. X
  1025. X    push_break();
  1026. X    if (ac == 1 && (mask & ST_DELETED) && Last_deleted != -1)  {
  1027. X    en = &Entry[Last_deleted];
  1028. X    if (en->no) {
  1029. X        en->status &= ~mask;
  1030. X        printf ("Undeleted last deleted message (# %d)\n", en->no);
  1031. X        Current = Last_deleted;
  1032. X        Last_deleted = -1;
  1033. X    } else {
  1034. X        puts ("Last deleted message not within current select bounds");
  1035. X        pop_break();
  1036. X        return (-1);
  1037. X    }
  1038. X    pop_break();
  1039. X    return (1);
  1040. X    }
  1041. X    rewind_range (1);
  1042. X    while (i = get_range()) {
  1043. X    j = indexof (i);
  1044. X    if (j >= 0) {
  1045. X        if (Entry[j].status & mask) {
  1046. X        Entry[j].status &= ~mask;
  1047. X        ++count;
  1048. X        }
  1049. X    }
  1050. X    }
  1051. X    if (!Silence)
  1052. X    printf ("%d  Items\n", count);
  1053. X    pop_break();
  1054. X    return (1);
  1055. X}
  1056. X
  1057. Xdo_break(garbage, mask)
  1058. Xchar *garbage;
  1059. X{
  1060. X    if (mask)
  1061. X    pop_break();
  1062. X    else
  1063. X    push_break();
  1064. X    return (1);
  1065. X}
  1066. X
  1067. Xvoid
  1068. Xdo_ver()
  1069. X{
  1070. X    puts (DVERSION);
  1071. X}
  1072. X
  1073. END_OF_FILE
  1074. if test 10526 -ne `wc -c <'uucp2/src/dmail/commands.c'`; then
  1075.     echo shar: \"'uucp2/src/dmail/commands.c'\" unpacked with wrong size!
  1076. fi
  1077. # end of 'uucp2/src/dmail/commands.c'
  1078. fi
  1079. if test -f 'uucp2/src/dmail/sendmail.c' -a "${1}" != "-c" ; then 
  1080.   echo shar: Will not clobber existing file \"'uucp2/src/dmail/sendmail.c'\"
  1081. else
  1082. echo shar: Extracting \"'uucp2/src/dmail/sendmail.c'\" \(9101 characters\)
  1083. sed "s/^X//" >'uucp2/src/dmail/sendmail.c' <<'END_OF_FILE'
  1084. X
  1085. X/*
  1086. X *  SENDMAIL.C
  1087. X *
  1088. X *  $Header: Beta:src/uucp/src/dmail/RCS/sendmail.c,v 1.1 90/02/02 12:04:06 dillon Exp Locker: dillon $
  1089. X *
  1090. X *  (C) Copyright 1985-1990 by Matthew Dillon,  All Rights Reserved.
  1091. X *
  1092. X *  Global Routines:    DO_REPLY()
  1093. X *            DO_MAIL()
  1094. X *
  1095. X *  Static Routines:    WORD_SIZE()
  1096. X *            FOPEN_SCRATCH()
  1097. X *            FREOPEN_SCRATCH()
  1098. X *            FCLOSE_SCRATCH()
  1099. X *            FTERMINATE_SCRATCH()
  1100. X *            DELETE_SCRATCH()
  1101. X *            RUN_VI()
  1102. X *            SEND_MAIL()
  1103. X *
  1104. X *
  1105. X */
  1106. X
  1107. X#include <stdio.h>
  1108. X#include <sys/types.h>
  1109. X#include <sys/stat.h>
  1110. X#include <sys/file.h>
  1111. X#ifdef UNIX
  1112. X#include <sys/ioctl.h>
  1113. X#endif
  1114. X#include <sys/time.h>
  1115. X#include <signal.h>
  1116. X#include "dmail.h"
  1117. X#include "config.h"
  1118. X
  1119. XFILE *fi;
  1120. Xchar file[64];
  1121. X
  1122. Xvoid fclose_scratch();
  1123. Xvoid fopen_scratch();
  1124. Xvoid copy_header();
  1125. Xvoid send_mail();
  1126. X
  1127. Xdo_reply(garbage, itext)
  1128. Xchar *garbage;
  1129. X{
  1130. X    int i, j;
  1131. X    int anyargs  = 0;
  1132. X    int len;
  1133. X    char *ptr;
  1134. X    static char buf[1024];
  1135. X    char *istr;
  1136. X
  1137. X    if (!(istr = get_var(LEVEL_SET, "_headchar")))
  1138. X    istr = ">";
  1139. X    if (push_base()) {
  1140. X    push_break();
  1141. X    pop_base();
  1142. X    fclose_scratch();
  1143. X    puts ("ABORTED, no mail sent");
  1144. X    unlink(file);
  1145. X    pop_break();
  1146. X    return (-1);
  1147. X    }
  1148. X    fopen_scratch();
  1149. X    strcpy (buf, "To: ");
  1150. X    for (i = 1; i < ac; ++i) {
  1151. X    if (*av[i] >= '0'  &&  *av[i] <= '9') {
  1152. X        if ((j = indexof(atoi(av[i]))) < 0) {
  1153. X        puts ("No such message");
  1154. X        fclose_scratch();
  1155. X        unlink(file);
  1156. X        pop_break();
  1157. X        return (-1);
  1158. X        }
  1159. X        Current = j;
  1160. X    } else {
  1161. X        if (anyargs)
  1162. X        strcat (buf, ", ");
  1163. X        anyargs = 1;
  1164. X        strcat (buf, av[i]);
  1165. X    }
  1166. X    }
  1167. X    len = strlen(buf);
  1168. X    switch (itext) {
  1169. X    case R_FORWARD:
  1170. X    strcat (buf, "\n");
  1171. X    fputs (buf, fi);
  1172. X    fputs ("Subject: \n", fi);
  1173. X    break;
  1174. X    case R_INCLUDE:
  1175. X    case R_REPLY:
  1176. X    if (anyargs) {
  1177. X        strcat (buf, ", ");
  1178. X        len = strlen(buf);
  1179. X    }
  1180. X    buf[len] = 0;
  1181. X    if (Current >= 0) {
  1182. X        char *rf = get_var(LEVEL_SET, "replyfields");
  1183. X        if (rf == NULL)
  1184. X        rf = "";
  1185. X        while (*rf) {       /* attempt to find the fields listed */
  1186. X        char *re;
  1187. X        char *ptr;
  1188. X        char c;
  1189. X        for (re = rf; *re && *re != ' ' && *re != 9; ++re);
  1190. X        c = *re;
  1191. X        *re = 0;
  1192. X        ptr = get_field(rf);
  1193. X        if (*ptr) {
  1194. X            *re = c;
  1195. X            sprintf (buf + len, "%s\n", ptr);
  1196. X            break;
  1197. X        }
  1198. X        *re = c;
  1199. X        while (*re == ' ' || *re == 9)
  1200. X            ++re;
  1201. X        rf = re;
  1202. X        }
  1203. X        if (*rf == 0) {
  1204. X        sprintf (buf + len, "%.*s\n",
  1205. X            word_size(Entry[Current].from), Entry[Current].from);
  1206. X        }
  1207. X    }
  1208. X    fputs (buf, fi);
  1209. X
  1210. X    fputs ("Cc: ", fi);
  1211. X    ptr = get_field ("Cc:");
  1212. X    if (*ptr)
  1213. X        fputs (ptr, fi);
  1214. X
  1215. X    fputs ("\nSubject: Re: ", fi);
  1216. X    fputs (get_field ("Subject:"), fi);
  1217. X    fputs ("\n", fi);
  1218. X    break;
  1219. X    case R_MAIL:
  1220. X    fputs (buf, fi);
  1221. X    fputs ("\n", fi);
  1222. X    fputs ("Cc: \n", fi);
  1223. X    fputs ("Bcc: \n", fi);
  1224. X    fputs ("Subject: \n", fi);
  1225. X    break;
  1226. X    default:
  1227. X    puts ("INTERNAL STUPID MAIL ERROR: REPLY");
  1228. X    break;
  1229. X    }
  1230. X    fputs ("\n\n", fi);
  1231. X    if (itext == R_FORWARD  ||  itext == R_INCLUDE) {
  1232. X    position_current();
  1233. X    if (itext == R_FORWARD) {
  1234. X        if (Current >= 0)
  1235. X        fprintf (fi, "ORIGINALLY From %s\n", Entry[Current].from);
  1236. X    } else {
  1237. X        skip_to_data (m_fi);
  1238. X    }
  1239. X    while ((fgets (Buf, MAXFIELDSIZE, m_fi) != NULL) && !isfrom(Buf)) {
  1240. X        if (itext == R_INCLUDE)
  1241. X        fputs(istr, fi);
  1242. X        fputs (Buf, fi);
  1243. X    }
  1244. X    fputs ("\n", fi);
  1245. X    }
  1246. X    copy_header (fi);
  1247. X    fclose_scratch();
  1248. X    if (itext != R_MAIL) {
  1249. X    push_break();
  1250. X    if (Current >= 0) {
  1251. X        Entry[Current].status |= ST_SCR;
  1252. X        write_file("t:Original", O_CREAT | O_TRUNC, ST_SCR, 0);
  1253. X        Entry[Current].status &= ~ST_SCR;
  1254. X    }
  1255. X    pop_break();
  1256. X    }
  1257. X    j = -1;
  1258. Xloop:
  1259. X    ++j;
  1260. X    if (run_vi() || j) {
  1261. X    push_break();
  1262. X    switch (do_ask()) {
  1263. X    case 1:
  1264. X        puts ("SENDING.. wait");
  1265. X        send_mail();
  1266. X        {
  1267. X        FILE *li = fopen(file, "r");
  1268. X        char buf[128], *ptr = NULL;
  1269. X
  1270. X        if (li) {
  1271. X            while (fgets(buf, 128, li) && buf[0] != '\n') {
  1272. X            if (strncmp(buf, "Farchive:", 9) == 0) {
  1273. X                buf[strlen(buf)-1] = '\0';
  1274. X                for (ptr = buf + 9; *ptr == ' '; ++ptr);
  1275. X                if (ptr[0] == '$')
  1276. X                ptr = get_var(LEVEL_SET, ptr+1);
  1277. X                break;
  1278. X            }
  1279. X            }
  1280. X            fclose(li);
  1281. X        }
  1282. X        archive_mail(ptr);
  1283. X        }
  1284. X        unlink(file);
  1285. X        break;
  1286. X    case 2:
  1287. X        pop_break();
  1288. X        goto loop;
  1289. X    default:
  1290. X        unlink (file);
  1291. X        break;
  1292. X    }
  1293. X    pop_base();
  1294. X    pop_break();
  1295. X    } else {
  1296. X    puts ("File not modified or ABORTED, no mail sent");
  1297. X    unlink(file);
  1298. X    pop_base();
  1299. X    }
  1300. X    unlink ("T:Original");
  1301. X}
  1302. X
  1303. Xdo_ask()
  1304. X{
  1305. X    char in[256];
  1306. X
  1307. X    if (!S_ask)
  1308. X    return (1);
  1309. X    fputs ("\n(Send, Vi, Quit) ?", stdout);
  1310. X    fflush(stdout);
  1311. X    gets (in);
  1312. X    switch (in[0]) {
  1313. X    case 's':
  1314. X    case 'S':
  1315. X    return (1);
  1316. X    case 'q':
  1317. X    case 'Q':
  1318. X    puts ("ABORT, no mail sent");
  1319. X    return (3);
  1320. X    case 'v':
  1321. X    case 'V':
  1322. X    default:
  1323. X    return (2);
  1324. X    }
  1325. X}
  1326. X
  1327. X
  1328. X
  1329. Xstatic void
  1330. Xcopy_header(fi)
  1331. XFILE *fi;
  1332. X{
  1333. X    FILE *fs;
  1334. X    char *ptr;
  1335. X    char *tmp = NULL;
  1336. X
  1337. X    if (ptr = get_var (LEVEL_SET, "header")) {
  1338. X    push_break();
  1339. X    fs = fopen(ptr, "r");
  1340. X    if (fs == NULL) {   /*  check uulib:    */
  1341. X        tmp = malloc(strlen(ptr) + strlen(MakeConfigPath(UULIB, "")) + 1);
  1342. X        sprintf(tmp, "%s%s", MakeConfigPath(UULIB, ""), ptr);
  1343. X        fs = fopen(tmp, "r");
  1344. X    }
  1345. X    if (fs) {
  1346. X        while (fgets (Buf, MAXFIELDSIZE, fs) != NULL)
  1347. X        fputs (Buf, fi);
  1348. X        fclose (fs);
  1349. X    } else {
  1350. X        printf ("Cannot open header file %d %s\n", strlen(ptr), ptr);
  1351. X        perror ("fopen");
  1352. X    }
  1353. X    if (tmp)
  1354. X        free(tmp);
  1355. X    pop_break();
  1356. X    }
  1357. X}
  1358. X
  1359. X
  1360. Xstatic void
  1361. Xfopen_scratch()
  1362. X{
  1363. X    static int c;
  1364. X    int fd;
  1365. X
  1366. X    sprintf(file, "t:dmt%d%d", getpid(), c++);
  1367. X    fd = open(file, O_RDWR|O_CREAT|O_TRUNC, 0700);
  1368. X    if (fd < 0) {
  1369. X    perror ("Dmail, cannot open scratch file");
  1370. X    done (1);
  1371. X    }
  1372. X#ifdef AMIGA        /*    fix bug in Lattice C fdopen */
  1373. X    fi = fopen("nil:", "w");
  1374. X    fclose(fi);
  1375. X#endif
  1376. X    fi = fdopen(fd, "w+");
  1377. X}
  1378. X
  1379. Xstatic void
  1380. Xfclose_scratch()
  1381. X{
  1382. X    if (fi != NULL) {
  1383. X    fflush (fi);
  1384. X    fclose (fi);
  1385. X    fi = NULL;
  1386. X    }
  1387. X}
  1388. X
  1389. X
  1390. Xstatic
  1391. Xword_size(str)
  1392. Xregister char *str;
  1393. X{
  1394. X    register int size = 0;
  1395. X
  1396. X    while (*str) {
  1397. X    if (*str == ' ')
  1398. X        return (size);
  1399. X    ++str;
  1400. X    ++size;
  1401. X    }
  1402. X    return (size);
  1403. X}
  1404. X
  1405. X
  1406. Xstatic
  1407. Xrun_vi()
  1408. X{
  1409. X#ifdef UNIX
  1410. X    char buf[64];
  1411. X    int ret, pid = 0;
  1412. X#endif
  1413. X    struct stat stat1, stat2;
  1414. X    char *argv[3];
  1415. X
  1416. X    argv[0] = visual;
  1417. X    argv[1] = file;
  1418. X    argv[2] = NULL;
  1419. X    if (push_base()) {
  1420. X    push_break();
  1421. X    pop_base();
  1422. X#ifdef UNIX
  1423. X    if (pid) {
  1424. X        kill (pid, SIGKILL);
  1425. X        sprintf (buf, "t:Ex%d", pid); unlink (buf);
  1426. X        sprintf (buf, "t:Rx%d", pid); unlink (buf);
  1427. X        wait(0);
  1428. X        system ("clear; reset ; clear");
  1429. X        pid = 0;
  1430. X    }
  1431. X#endif
  1432. X    pop_break();
  1433. X    return (0);
  1434. X    }
  1435. X    stat1.st_mtime = stat2.st_mtime = stat1.st_ctime = stat2.st_ctime = 0;
  1436. X    stat (file, &stat1);
  1437. X    if (S_novibreak)
  1438. X    push_break();
  1439. X
  1440. X#ifdef UNIX
  1441. X    pid = vfork();
  1442. X    if (!pid) {
  1443. X    execv (visual, argv);
  1444. X    printf ("Cannot exec visual: %s\n", visual);
  1445. X    _exit (1);
  1446. X    }
  1447. X    while ((ret = wait(0)) > 0) {
  1448. X    if (ret == pid)
  1449. X        break;
  1450. X    }
  1451. X#endif
  1452. X#ifdef AMIGA
  1453. X    {
  1454. X    short i;
  1455. X    static char buf[128];
  1456. X
  1457. X    strcpy(buf, argv[0]);
  1458. X    for (i = 1; argv[i]; ++i) {
  1459. X        strcat(buf, " ");
  1460. X        strcat(buf, argv[i]);
  1461. X    }
  1462. X    Execute(buf, NULL, NULL);
  1463. X    }
  1464. X#endif
  1465. X    if (S_novibreak)
  1466. X    pop_break();
  1467. X    stat (file, &stat2);
  1468. X    pop_base();
  1469. X    return (!(stat1.st_mtime==stat2.st_mtime));
  1470. X}
  1471. X
  1472. X
  1473. X#ifdef UNIX
  1474. X
  1475. Xstatic void
  1476. Xsend_mail()
  1477. X{
  1478. X    int fd, stdin_fd;
  1479. X    char *argv[6];
  1480. X
  1481. X    push_break();
  1482. X    argv[0] = S_sendmail;
  1483. X    argv[1] = "-t";
  1484. X    argv[2] = "-oem";
  1485. X    argv[3] = "-i";
  1486. X    if (S_verbose) {
  1487. X    argv[4] = "-v";
  1488. X    argv[5] = NULL;
  1489. X    } else {
  1490. X    argv[4] = NULL;
  1491. X    }
  1492. X
  1493. X    fd = open (file, O_RDONLY, 0);
  1494. X    if (fd < 0) {
  1495. X    perror ("Dmail, Cannot open scratch file");
  1496. X    done (1);
  1497. X    }
  1498. X    lseek(fd, 0L, 0);
  1499. X
  1500. X    stdin_fd = dup (0);
  1501. X    dup2 (fd, 0);       /* STDIN = message file */
  1502. X    close(fd);          /* don't need message file anymore  */
  1503. X    if (!fork()) {
  1504. X    int fd = open("/dev/tty", O_RDWR, 0);
  1505. X    if (fd >= 0) {
  1506. X        ioctl(fd, TIOCNOTTY, 0);
  1507. X        close(fd);
  1508. X        freopen("/dev/null", "w", stdout);
  1509. X        freopen("/dev/null", "w", stderr);
  1510. X    }
  1511. X    execv (S_sendmail, argv);
  1512. X    printf ("Unable to exec sendmail: %s\n", S_sendmail);
  1513. X    _exit (1);
  1514. X    }
  1515. X    dup2 (stdin_fd, 0);     /* restore STDIN    */
  1516. X    close(stdin_fd);
  1517. X    if (S_verbose) {
  1518. X    puts ("Waiting for sendmail...");
  1519. X    wait (0);
  1520. X    puts ("Sendmail done");
  1521. X    }
  1522. X    pop_break();
  1523. X}
  1524. X
  1525. X#endif
  1526. X#ifdef AMIGA
  1527. X
  1528. Xstatic void
  1529. Xsend_mail()
  1530. X{
  1531. X    static char Buf[256];
  1532. X
  1533. X    push_break();
  1534. X    sprintf(Buf, "%s < %s%s -f %s", S_sendmail, file, (S_verbose ? " -v" : ""), user_name);
  1535. X
  1536. X    printf("Sending\n", Buf);
  1537. X    if (Execute(Buf, NULL, NULL) == 0)
  1538. X    printf("Unable to run: %s\n", Buf);
  1539. X
  1540. X    pop_break();
  1541. X}
  1542. X
  1543. X#endif
  1544. X
  1545. X
  1546. X
  1547. X
  1548. X
  1549. Xstatic
  1550. Xarchive_mail(ptr)
  1551. Xchar *ptr;
  1552. X{
  1553. X    FILE *ifi, *ofi;
  1554. X    long tim = time(NULL);
  1555. X
  1556. X    if (!ptr)
  1557. X    ptr = get_var(LEVEL_SET, "archive");
  1558. X    if (ptr == NULL || *ptr == '\0')
  1559. X    return(-1);
  1560. X    ifi = fopen(file, "r");
  1561. X    if (ifi == NULL) {
  1562. X    puts ("Cannot open scratch file");
  1563. X    return(-1);
  1564. X    }
  1565. X    ofi = fopen(ptr, "a");
  1566. X    if (ofi == NULL) {
  1567. X    puts ("Cannot open archive file");
  1568. X    fclose(ifi);
  1569. X    return(-1);
  1570. X    }
  1571. X    sprintf (Buf, "\nFrom %s (ARCHIVE)\n", user_name);
  1572. X    fputs (Buf, ofi);
  1573. X    sprintf (Buf, "Date: %s", ctime(&tim));
  1574. X    fputs (Buf, ofi);
  1575. X    while (fgets (Buf, MAXFIELDSIZE, ifi))
  1576. X    fputs (Buf, ofi);
  1577. X    fclose(ofi);
  1578. X    fclose(ifi);
  1579. X    return (1);
  1580. X}
  1581. X
  1582. X
  1583. END_OF_FILE
  1584. if test 9101 -ne `wc -c <'uucp2/src/dmail/sendmail.c'`; then
  1585.     echo shar: \"'uucp2/src/dmail/sendmail.c'\" unpacked with wrong size!
  1586. fi
  1587. # end of 'uucp2/src/dmail/sendmail.c'
  1588. fi
  1589. if test -f 'uucp2/src/unix/dcron.c' -a "${1}" != "-c" ; then 
  1590.   echo shar: Will not clobber existing file \"'uucp2/src/unix/dcron.c'\"
  1591. else
  1592. echo shar: Extracting \"'uucp2/src/unix/dcron.c'\" \(10992 characters\)
  1593. sed "s/^X//" >'uucp2/src/unix/dcron.c' <<'END_OF_FILE'
  1594. X
  1595. X/*
  1596. X *  DCRON.C  V2
  1597. X *
  1598. X *  - loads s:crontab or file crontab specified by -f
  1599. X *  - checks the datestamp on s:crontab every 60 seconds and reloads the file
  1600. X *    into memory if changed.
  1601. X *  - every 60 seconds scans the memory-resident image for things to do
  1602. X *  - checks for date changes and doesn't reexecute if changes are
  1603. X *    backwards in time.
  1604. X *
  1605. X *  DCRON [-d] [-f crontab] logfile
  1606. X */
  1607. X
  1608. X#include <exec/types.h>
  1609. X#include <devices/timer.h>
  1610. X#include <libraries/dos.h>
  1611. X#include <libraries/dosextens.h>
  1612. X#include <stdio.h>
  1613. X#include "protos.h"
  1614. X
  1615. Xtypedef struct Node    NODE;
  1616. Xtypedef struct List    LIST;
  1617. Xtypedef struct DateStamp DATESTAMP;
  1618. Xtypedef struct timerequest IOT;
  1619. Xtypedef struct MsgPort    PORT;
  1620. Xtypedef struct Process    PROC;
  1621. Xtypedef struct FileInfoBlock FIB;
  1622. X
  1623. X
  1624. X#define CRONTAB "s:crontab"
  1625. X#define SIGS    (SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F)
  1626. X
  1627. Xtypedef struct {
  1628. X    short min;
  1629. X    short hour;
  1630. X    short day;
  1631. X    short month;
  1632. X    short dow;
  1633. X} DateAry;
  1634. X
  1635. Xtypedef struct {
  1636. X    NODE    Node;
  1637. X    UBYTE   BitMap[8][8];   /*    min, hour, day, month, dow */
  1638. X    char    *Command;
  1639. X} Command;
  1640. X
  1641. Xextern    char *malloc();
  1642. X
  1643. XDATESTAMP   LastDate;        /*    Date as of last execution    */
  1644. XDATESTAMP   ModDate;        /*    Check if system time  modified    */
  1645. XDATESTAMP   TabDate;        /*    Check if crontab modified    */
  1646. X
  1647. XLIST        CmdList;        /*    list of commands        */
  1648. X
  1649. XIOT    Iot;
  1650. XPORT    *TPort;         /*    Collector plate for IO requests     */
  1651. Xshort    FatalError;        /*    Uh oh, can't recover                    */
  1652. Xchar    *LogFile;
  1653. Xchar    *CronFile = CRONTAB;
  1654. Xchar    XDebug;
  1655. Xlong    NilFH;            /*    NIL: file handle            */
  1656. Xshort    CronFileExists = 0; /*    -1, 0, 1                */
  1657. X
  1658. Xvoid    logmessage();
  1659. Xvoid    LoadCronFile();
  1660. Xvoid    LoadBitMap();
  1661. Xvoid    WriteStr();
  1662. Xvoid    RunCommand();
  1663. Xvoid    ExecuteCommands();
  1664. Xvoid    CheckFileModified();
  1665. Xvoid    DateToDateAry();
  1666. Xvoid    *GetHead();
  1667. Xvoid    *GetSucc();
  1668. X
  1669. Xint
  1670. Xbrk()
  1671. X{
  1672. X    return(0);
  1673. X}
  1674. X
  1675. Xvoid
  1676. Xmain(ac, av)
  1677. Xshort ac;
  1678. Xchar *av[];
  1679. X{
  1680. X    PROC *proc = (PROC *)FindTask(NULL);
  1681. X    APTR oldConsoleTask = proc->pr_ConsoleTask;
  1682. X
  1683. X    onbreak(brk);
  1684. X    NewList(&CmdList);
  1685. X    {
  1686. X    register short i;
  1687. X
  1688. X    for (i = 1; i < ac; ++i) {
  1689. X        register char *ptr = av[i];
  1690. X        if (*ptr != '-') {
  1691. X        LogFile = ptr;
  1692. X        continue;
  1693. X        }
  1694. X        while (*++ptr) {
  1695. X        switch(*ptr) {
  1696. X        case 'd':
  1697. X            ++XDebug;
  1698. X            break;
  1699. X        case 'f':
  1700. X            CronFile = av[++i];
  1701. X            break;
  1702. X        default:
  1703. X            WriteStr(Output(), "bad option\n");
  1704. X            goto fail;
  1705. X        }
  1706. X        }
  1707. X    }
  1708. X    if (CronFile == NULL) {
  1709. X        puts("-f : expected filename");
  1710. X        exit(1);
  1711. X    }
  1712. X    }
  1713. X    if (!LogFile) {
  1714. Xfail:
  1715. X    WriteStr(Output(), "DCron [-d] [-f cronfile] Logfile\n");
  1716. X    WriteStr(Output(), "DCron, V2.02\n");
  1717. X    exit(1);
  1718. X    }
  1719. X    if (OpenDevice("timer.device", 0, &Iot, UNIT_VBLANK)) {
  1720. X    logmessage("Unable to open timer.device\n");
  1721. X    exit(1);
  1722. X    }
  1723. X    if (!DeviceProc("NULL:")) {
  1724. X    logmessage("NULL: device required for dcron to run\n");
  1725. X    WriteStr(Output(), "NULL: device required to run\n");
  1726. X    exit(1);
  1727. X    }
  1728. X    proc->pr_ConsoleTask = (APTR)DeviceProc("NULL:");
  1729. X    fclose(stderr);
  1730. X
  1731. X    logmessage("Startup: V2.02 (dist: 29 May 1990)\n");
  1732. X
  1733. X    NilFH = (long)Open("null:", 1006);
  1734. X    DateStamp(&LastDate);
  1735. X    DateStamp(&ModDate);
  1736. X    TPort = CreatePort(NULL,0);
  1737. X    Iot.tr_time.tv_secs = 2;
  1738. X    Iot.tr_time.tv_micro= 0;
  1739. X    Iot.tr_node.io_Message.mn_ReplyPort = TPort;
  1740. X    Iot.tr_node.io_Command = TR_ADDREQUEST;
  1741. X    SendIO(&Iot);                                   /*  timeout */
  1742. X
  1743. X    for (;;) {
  1744. X    long mask;
  1745. X    mask = Wait(SIGS | (1 << TPort->mp_SigBit));
  1746. X    if (mask & (SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D)) {
  1747. X        logmessage("DCRON: Break\n");
  1748. X        break;
  1749. X    }
  1750. X    if (mask & (SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F)) {
  1751. X        logmessage("^E/F force check\n");
  1752. X        AbortIO(&Iot);          /*  force execution                     */
  1753. X    }
  1754. X    if (FatalError)
  1755. X        break;
  1756. X    if (CheckIO(&Iot)) {        /*  if file/date modified, force exec.  */
  1757. X        DATESTAMP Ds;
  1758. X        DateAry D1, D2;
  1759. X        int st;
  1760. X
  1761. X        WaitIO(&Iot);
  1762. X        st = CheckDateChanged();
  1763. X        CheckFileModified();
  1764. X        DateStamp(&Ds);
  1765. X        DateToDateAry(&LastDate, &D1);
  1766. X        DateToDateAry(&Ds, &D2);
  1767. X        if (st == 0)
  1768. X        ExecuteCommands(&D1, &D2);
  1769. X        LastDate = Ds;
  1770. X        DateStamp(&Ds);
  1771. X        Iot.tr_time.tv_secs = 61 - Ds.ds_Tick / 50;
  1772. X        Iot.tr_time.tv_micro= 0;
  1773. X        SendIO(&Iot);
  1774. X    }
  1775. X    }
  1776. X    AbortIO(&Iot);
  1777. X    WaitIO(&Iot);
  1778. X    CloseDevice(&Iot);
  1779. X    DeletePort(TPort);
  1780. X    Close(NilFH);
  1781. X    proc->pr_ConsoleTask = oldConsoleTask;
  1782. X}
  1783. X
  1784. X/*
  1785. X *  Returns 0 = execute objects for range
  1786. X *        1 = do not execute objects for range
  1787. X */
  1788. X
  1789. XCheckDateChanged()
  1790. X{
  1791. X    DATESTAMP Ds;
  1792. X    long xold, xnew;
  1793. X    static char state = 0;
  1794. X
  1795. X    DateStamp(&Ds);
  1796. X    xold = ModDate.ds_Days * 1440 + ModDate.ds_Minute;
  1797. X    xnew = Ds.ds_Days * 1440 + Ds.ds_Minute;
  1798. X
  1799. X    /*
  1800. X     *    if backwards or more than T+5min
  1801. X     */
  1802. X
  1803. X    if (xnew < xold || xnew - 5 > xold) {
  1804. X    DateStamp(&LastDate);
  1805. X    if (state == 0)
  1806. X        logmessage("Date change noted, %d mins\n", xnew - xold + 1);
  1807. X    state = 1;
  1808. X    } else {
  1809. X    state = 0;
  1810. X    }
  1811. X
  1812. X    /*
  1813. X     *    If all is ok or too far away from old date then set new base
  1814. X     *    date for next comparison (T +/- 10min)
  1815. X     */
  1816. X
  1817. X    if (state == 0 || xold - xnew > 10 || xold - xnew < -10 ) {
  1818. X    ModDate = Ds;
  1819. X    }
  1820. X    return((int)state);
  1821. X}
  1822. X
  1823. Xvoid
  1824. XCheckFileModified()
  1825. X{
  1826. X    char buf[sizeof(FIB)+4];
  1827. X    long lock;
  1828. X
  1829. X    if (lock = (long)Lock(CronFile, SHARED_LOCK)) {
  1830. X    register FIB *fib = (FIB *)(((long)buf+3)&~3);
  1831. X    if (Examine(lock, fib)) {
  1832. X        if (CronFileExists < 1 ||
  1833. X        fib->fib_Date.ds_Tick    != TabDate.ds_Tick ||
  1834. X        fib->fib_Date.ds_Minute != TabDate.ds_Minute ||
  1835. X        fib->fib_Date.ds_Days    != TabDate.ds_Days)
  1836. X        {
  1837. X        if (TabDate.ds_Days) {
  1838. X            logmessage("crontab modification noted\n");
  1839. X        }
  1840. X        TabDate = fib->fib_Date;
  1841. X        LoadCronFile();
  1842. X        }
  1843. X    }
  1844. X    UnLock(lock);
  1845. X    } else {
  1846. X    if (CronFileExists >= 0) {
  1847. X        logmessage("unable to lock cronfile %s!\n", CronFile);
  1848. X        CronFileExists = -1;
  1849. X    }
  1850. X    }
  1851. X}
  1852. X
  1853. X/*
  1854. X *  execute commands that fall d1 < cmd <= d2
  1855. X */
  1856. X
  1857. Xvoid
  1858. XExecuteCommands(d1, d2)
  1859. Xshort *d1, *d2;     /*    min, hour, day, month, dow  */
  1860. X{
  1861. X    Command *cmd;
  1862. X    short i;
  1863. X    short n;
  1864. X
  1865. X    for (cmd = GetHead(&CmdList); cmd; cmd = GetSucc(&cmd->Node)) {
  1866. X    short ok = 1;
  1867. X    for (i = 0; i < 5; ++i) {
  1868. X        UBYTE *bitmap = cmd->BitMap[i];
  1869. X
  1870. X        n = d2[i];
  1871. X        if (n == d1[i]) {
  1872. X        if ((bitmap[n>>3] & (1 << (n & 7))) == 0) {
  1873. X            ok = 0;
  1874. X            break;
  1875. X        }
  1876. X        } else {
  1877. X        while (n != d1[i]) {
  1878. X            if (bitmap[n>>3] & (1 << (n & 7)))
  1879. X            break;
  1880. X            n = (n - 1) & 63;
  1881. X        }
  1882. X        if (n == d1[i]) {
  1883. X            ok = 0;
  1884. X            break;
  1885. X        }
  1886. X        }
  1887. X    }
  1888. X    if (ok)
  1889. X        RunCommand(cmd->Command);
  1890. X    }
  1891. X}
  1892. X
  1893. Xvoid
  1894. XRunCommand(cmd)
  1895. Xchar *cmd;
  1896. X{
  1897. X    char buf[256];
  1898. X
  1899. X    logmessage("%s\n", cmd);
  1900. X    strcpy(buf, "run ");
  1901. X    strcat(buf, cmd);
  1902. X    Execute(buf, NilFH, NilFH);
  1903. X}
  1904. X
  1905. Xvoid
  1906. XDateToDateAry(date, da)
  1907. XDATESTAMP *date;
  1908. XDateAry *da;
  1909. X{
  1910. X    static char dim[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  1911. X    long days;
  1912. X    long years;
  1913. X    char leap;
  1914. X    short month;
  1915. X
  1916. X    days = date->ds_Days + 731;         /*    1976        */
  1917. X    years = days / (365*3+366);             /*  #quad yrs   */
  1918. X    days -= years * (365*3+366);
  1919. X    leap = (days <= 365);                   /*  is a leap yr*/
  1920. X    years = 1976 + 4 * years;
  1921. X    dim[1] = 29;
  1922. X    if (leap == 0) {
  1923. X    dim[1] = 28;
  1924. X    days -= 366;
  1925. X    ++years;
  1926. X    years += days / 365;
  1927. X    days %= 365;
  1928. X    }
  1929. X    for (month = 0; (month==1) ? (days >= 28 + leap) : (days >= dim[month]); ++month)
  1930. X    days -= (month==1) ? (28 + leap) : dim[month];
  1931. X
  1932. X    da->min    = date->ds_Minute % 60;
  1933. X    da->hour   = date->ds_Minute / 60;
  1934. X    da->day    = days + 1;
  1935. X    da->month  = month + 1;
  1936. X    da->dow    = date->ds_Days % 7;    /*  0 = sunday    */
  1937. X}
  1938. X
  1939. Xvoid
  1940. XLoadCronFile()
  1941. X{
  1942. X    char buf[256];
  1943. X    long fh;
  1944. X    Command *cmd;
  1945. X
  1946. X    while (cmd = (Command *)RemHead(&CmdList))
  1947. X    free(cmd);
  1948. X
  1949. X    ReadLn(NULL, NULL, 0);
  1950. X    fh = (long)Open(CronFile, 1005);
  1951. X    if (fh == NULL) {
  1952. X    if (CronFileExists != -1)
  1953. X        logmessage("unable to open cronfile %s!\n", CronFile);
  1954. X    CronFileExists = -1;
  1955. X    return;
  1956. X    }
  1957. X    while (ReadLn(fh, buf, 256)) {
  1958. X    char *ptr = buf;
  1959. X    short i;
  1960. X
  1961. X    if (buf[0] == 0 || buf[0] == '#')
  1962. X        continue;
  1963. X    cmd = (Command *)malloc(sizeof(Command));
  1964. X    setmem(cmd, sizeof(Command), 0);
  1965. X
  1966. X    for (i = 0; i < 5; ++i) {               /*  5 time fields   */
  1967. X        /*
  1968. X        printf("lb %d\n", i);
  1969. X        */
  1970. X        LoadBitMap(&ptr, cmd->BitMap[i]);
  1971. X    }
  1972. X
  1973. X    while (*ptr == ' ' || *ptr == 9)
  1974. X        ++ptr;
  1975. X    cmd->Command = malloc(strlen(ptr) + 1);
  1976. X    strcpy(cmd->Command, ptr);
  1977. X
  1978. X    /*
  1979. X    for (i = 0; i < 5; ++i) {
  1980. X        for (j = 0; j < 4; ++j)
  1981. X        printf("%02x", cmd->BitMap[i][j]);
  1982. X        printf(" ");
  1983. X        for (j = 4; j < 8; ++j)
  1984. X        printf("%02x", cmd->BitMap[i][j]);
  1985. X        puts("");
  1986. X    }
  1987. X
  1988. X    printf("cmd = %s\n", cmd->Command);
  1989. X    */
  1990. X
  1991. X    AddTail(&CmdList, &cmd->Node);
  1992. X    }
  1993. X    Close(fh);
  1994. X    CronFileExists = 1;
  1995. X}
  1996. X
  1997. Xvoid
  1998. XLoadBitMap(pptr, bm)
  1999. Xchar **pptr;
  2000. XUBYTE *bm;    /*  8 bytes = 64 entries    */
  2001. X{
  2002. X    register char *ptr = *pptr;
  2003. X
  2004. X    while (*ptr == ' ' || *ptr == 9)
  2005. X    ++ptr;
  2006. X
  2007. X    /*
  2008. X     *    looking for *, number range n-n, single numbers, etc...  1,2,8-10 ...
  2009. X     */
  2010. X
  2011. X    while (*ptr == '*' || (*ptr >= '0' && *ptr <= '9')) {
  2012. X    short v1, v2;
  2013. X
  2014. X    v1 = 0;
  2015. X    while (*ptr >= '0' && *ptr <= '9') {
  2016. X        v1 = v1 * 10 + *ptr - '0';
  2017. X        ++ptr;
  2018. X    }
  2019. X    if (*ptr == '-') {
  2020. X        ++ptr;
  2021. X        v2 = 0;
  2022. X        while (*ptr >= '0' && *ptr <= '9') {
  2023. X        v2 = v2 * 10 + *ptr - '0';
  2024. X        ++ptr;
  2025. X        }
  2026. X    } else {
  2027. X        v2 = v1;
  2028. X    }
  2029. X    if (*ptr == '*') {
  2030. X        v1 = 0;
  2031. X        v2 = 63;
  2032. X        ++ptr;
  2033. X    }
  2034. X    if (v1 < 0)
  2035. X        v1 = 0;
  2036. X    if (v1 > 63)
  2037. X        v1 = 63;
  2038. X    if (v2 < 0)
  2039. X        v2 = 0;
  2040. X    if (v2 > 63)
  2041. X        v2 = 63;
  2042. X
  2043. X    --v1;
  2044. X    do {
  2045. X        v1 = (v1 + 1) & 63;
  2046. X        bm[v1>>3] |= (1 << (v1 & 7));
  2047. X    } while (v1 != v2);
  2048. X    if (*ptr == ',')
  2049. X        ++ptr;
  2050. X    }
  2051. X    *pptr = ptr;
  2052. X}
  2053. X
  2054. X/*
  2055. X *  Poor man's log.  Note that the log file is not left open ... this allows
  2056. X *  one to read or tail it at any time.
  2057. X */
  2058. X
  2059. Xvoid
  2060. Xlogmessage(ptr, a, b, c, d, e)
  2061. Xchar *ptr;
  2062. X{
  2063. X    char *buf = malloc(512);
  2064. X    DATESTAMP date;
  2065. X    DateAry da;
  2066. X    long    fh;
  2067. X    static char *Dow[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  2068. X    static char *Miy[] = { "---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  2069. X               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  2070. X
  2071. X    if (!buf)
  2072. X    return;
  2073. X
  2074. X    DateStamp(&date);
  2075. X    DateToDateAry(&date, &da);
  2076. X
  2077. X    sprintf(buf, "dcron: %s %2ld %s %02ld:%02ld   ",
  2078. X    Dow[da.dow], da.day, Miy[da.month], da.hour, da.min
  2079. X    );
  2080. X    sprintf(buf+strlen(buf), ptr, a, b, c, d, e);
  2081. X    if ((fh = (long)Open(LogFile, 1005)) == NULL)
  2082. X    fh = (long)Open(LogFile, 1006);
  2083. X    if (fh) {
  2084. X    Seek(fh, 0L, 1);
  2085. X    WriteStr(fh, buf);
  2086. X    Close(fh);
  2087. X    }
  2088. X    free(buf);
  2089. X}
  2090. X
  2091. Xvoid
  2092. XWriteStr(fh, buf)
  2093. Xlong fh;
  2094. Xchar *buf;
  2095. X{
  2096. X    Write(fh, buf, strlen(buf));
  2097. X}
  2098. X
  2099. XReadLn(fh, buf, max)
  2100. Xlong fh;
  2101. Xchar *buf;
  2102. Xshort max;
  2103. X{
  2104. X    static char Data[1024];
  2105. X    static short RIdx, RLen;
  2106. X    register short i;
  2107. X
  2108. X    if (fh == NULL) {
  2109. X    RIdx = RLen = 0;
  2110. X    return(0);
  2111. X    }
  2112. X    for (--max, i = 0; i < max; ++i) {
  2113. X    if (RIdx == RLen) {
  2114. X        RLen = Read(fh, Data, 1024);
  2115. X        RIdx = 0;
  2116. X        if (RLen <= 0) {
  2117. X        buf[i] = 0;
  2118. X        return(0);
  2119. X        }
  2120. X    }
  2121. X    if ((buf[i] = Data[RIdx++]) == '\n')
  2122. X        break;
  2123. X    }
  2124. X    buf[i] = 0;
  2125. X    return(1);
  2126. X}
  2127. X
  2128. END_OF_FILE
  2129. if test 10992 -ne `wc -c <'uucp2/src/unix/dcron.c'`; then
  2130.     echo shar: \"'uucp2/src/unix/dcron.c'\" unpacked with wrong size!
  2131. fi
  2132. # end of 'uucp2/src/unix/dcron.c'
  2133. fi
  2134. if test -f 'uucp2/src/uucico/sysdep.c' -a "${1}" != "-c" ; then 
  2135.   echo shar: Will not clobber existing file \"'uucp2/src/uucico/sysdep.c'\"
  2136. else
  2137. echo shar: Extracting \"'uucp2/src/uucico/sysdep.c'\" \(11990 characters\)
  2138. sed "s/^X//" >'uucp2/src/uucico/sysdep.c' <<'END_OF_FILE'
  2139. X
  2140. X/*
  2141. X *  SYSDEP.C
  2142. X *
  2143. X *  $Header: Beta:src/uucp/src/uucico/RCS/sysdep.c,v 1.1 90/02/02 11:56:16 dillon Exp Locker: dillon $
  2144. X *
  2145. X * (C) Copyright 1987 by John Gilmore
  2146. X * Copying and use of this program are controlled by the terms of the Free
  2147. X * Software Foundation's GNU Emacs General Public License.
  2148. X *
  2149. X *  Amiga Changes Copyright 1988 by William Loftus. All rights reserved.
  2150. X *  Additional chgs Copyright 1989 by Matthew Dillon, All Rights Reserved.
  2151. X */
  2152. X
  2153. X#include "includes.h"
  2154. X#include <hardware/cia.h>
  2155. X#include <libraries/dos.h>
  2156. X#include <pwd.h>
  2157. X#include "uucp.h"
  2158. X#include "version.h"
  2159. X
  2160. XPrototype int openout(char *, int);
  2161. XPrototype int sigint(void);
  2162. XPrototype void cleanup(void);
  2163. XPrototype int xdatardy(void);
  2164. XPrototype int xgetc(int);
  2165. XPrototype int xwrite(const void *, int);
  2166. XPrototype int xwritea(const void *, int);
  2167. XPrototype int xxwrite(const void *, int, int);
  2168. XPrototype void SendBreak(void);
  2169. XPrototype int CheckCarrier(void);
  2170. XPrototype void *bzero(void *, long);
  2171. XPrototype void *bcopy(const void *, void *, long);
  2172. XPrototype void munge_filename(char *, char *);
  2173. XPrototype int hangup(void);
  2174. XPrototype char *work_scan(char *);
  2175. XPrototype char *work_next(void);
  2176. XPrototype void amiga_closeopen(char *);
  2177. XPrototype void amiga_setup(void);
  2178. XPrototype void set_baud(int);
  2179. XPrototype void OpenSerial(void);
  2180. XPrototype void CloseSerial(void);
  2181. XPrototype void xexit(int);
  2182. XPrototype void printc(unsigned char);
  2183. X
  2184. XIDENT(".03");
  2185. X
  2186. X/*
  2187. X *  Split out of uuslave.c by John Gilmore, 8 August 1987.
  2188. X *  ported to the Amiga by William Loftus, 20 September 1987.
  2189. X *  rewritten by Matthew Dillon, October 1989
  2190. X */
  2191. X
  2192. X/* FIXME -- System dependent defines (not really -- should be in a .h) */
  2193. X/*
  2194. X * Timeout for raw characters -- if we don't hear a char within BYTE_TIMEOUT
  2195. X * seconds, we assume the other side has gone away.  Has nothing to do with
  2196. X * retransmission timeouts (if any!).
  2197. X */
  2198. X
  2199. Xextern int debug;
  2200. Xextern int SevenWire;
  2201. X
  2202. X#define FAILURE  1
  2203. X
  2204. Xstruct IOExtSer Iosr;
  2205. Xstruct IOExtSer Iosw;
  2206. Xstruct IOExtSer Ioss;
  2207. Xstruct timerequest Iot0;
  2208. Xchar   *OldTaskName;
  2209. X
  2210. Xchar    *DeviceName = "serial.device";
  2211. Xlong    DeviceUnit = 0;
  2212. X
  2213. Xunsigned char    XInBuf[256];       /*  for xgetc() */
  2214. Xshort    XInIdx = 0;
  2215. Xshort    XInLen = 0;
  2216. Xshort    IoswIP = 0;
  2217. X
  2218. Xshort    InExitRoutine = 0;
  2219. Xshort    debugRead = 0;
  2220. X
  2221. Xextern char path[];
  2222. Xextern int Getty;
  2223. Xextern int IgnoreCD;
  2224. X
  2225. Xint
  2226. Xopenout(acu, baud)
  2227. Xchar *acu;
  2228. Xint  baud;
  2229. X{
  2230. X    set_baud(baud);
  2231. X
  2232. X    return SUCCESS;
  2233. X}
  2234. X
  2235. X/*
  2236. X * Basement level I/O routines
  2237. X *
  2238. X * xwrite() writes a character string to the serial port
  2239. X * xgetc() returns a character from the serial port, or an EOF for timeout.
  2240. X * sigint() restores the state of the serial port on exit.
  2241. X */
  2242. X
  2243. Xint
  2244. Xsigint()
  2245. X{
  2246. X    xexit(1);
  2247. X    return(0);
  2248. X}
  2249. X
  2250. X
  2251. Xvoid
  2252. Xcleanup()
  2253. X{
  2254. X    xexit(0);
  2255. X}
  2256. X
  2257. Xint
  2258. Xxdatardy()
  2259. X{
  2260. X    if (XInIdx != XInLen)
  2261. X    return(1);
  2262. X    CheckCarrier();
  2263. X    return (Ioss.IOSer.io_Actual > 0);
  2264. X}
  2265. X
  2266. Xint
  2267. Xxgetc(byteto)
  2268. Xint byteto;
  2269. X{
  2270. X    int ch, n;
  2271. X    long smask;
  2272. X    long tmask;
  2273. X    short bytetimeout;
  2274. X
  2275. Xtop:
  2276. X    if (XInIdx != XInLen) {
  2277. X    if (debug > 8) {
  2278. X        if (debugRead == 0)
  2279. X        printf("\nREAD: ");
  2280. X        debugRead = 1;
  2281. X        printc(XInBuf[XInIdx]);
  2282. X    }
  2283. X    return((int)XInBuf[XInIdx++]);
  2284. X    }
  2285. X    XInIdx = 0;
  2286. X    XInLen = 0;
  2287. X
  2288. X    if (!CheckCarrier())                        /*  carrier lost?     */
  2289. X    return(EOF);
  2290. X
  2291. X    if ((n = Ioss.IOSer.io_Actual) > 0) {       /*  at least one..    */
  2292. X    Iosr.IOSer.io_Command = CMD_READ;
  2293. X    Iosr.IOSer.io_Data = (APTR)XInBuf;
  2294. X    if (n > sizeof(XInBuf))
  2295. X        n = sizeof(XInBuf);
  2296. X    Iosr.IOSer.io_Length = n;
  2297. X    DoIO(&Iosr);
  2298. X    if (Iosr.IOSer.io_Actual > 0) {
  2299. X        if (debug > 8)
  2300. X        printf("(r%d/%d)", n, Iosr.IOSer.io_Actual);
  2301. X        XInIdx = 0;
  2302. X        XInLen = Iosr.IOSer.io_Actual;
  2303. X        goto top;
  2304. X    }
  2305. X    }
  2306. X
  2307. X    /*
  2308. X     *    no bytes ready, byteto is 0 (no wait)
  2309. X     */
  2310. X
  2311. X    if (byteto == 0)
  2312. X    return(EOF);
  2313. X
  2314. X    /*
  2315. X     *    no bytes ready, wait for one.
  2316. X     *
  2317. X     *    once every 3 seconds check carrier detect.
  2318. X     */
  2319. X
  2320. X    bytetimeout = byteto;
  2321. X    Iot0.tr_time.tv_secs = 3;
  2322. X    Iot0.tr_time.tv_micro= 0;
  2323. X    SendIO(&Iot0);
  2324. X
  2325. X    Iosr.IOSer.io_Command = CMD_READ;
  2326. X    Iosr.IOSer.io_Data = (APTR)XInBuf;
  2327. X    Iosr.IOSer.io_Length = 1;
  2328. X    Iosr.IOSer.io_Actual = 0;    /*  trying to find a bug... */
  2329. X    SendIO(&Iosr);
  2330. X
  2331. X    smask = 1L << Iosr.IOSer.io_Message.mn_ReplyPort->mp_SigBit;
  2332. X    tmask = 1L << Iot0.tr_node.io_Message.mn_ReplyPort->mp_SigBit;
  2333. X
  2334. X    for (;;) {
  2335. X    long mask = Wait(tmask | smask | SIGBREAKF_CTRL_C);
  2336. X
  2337. X    if (mask & SIGBREAKF_CTRL_C) {
  2338. X        AbortIO(&Iosr);
  2339. X        WaitIO(&Iosr);
  2340. X        AbortIO(&Iot0);
  2341. X        WaitIO(&Iot0);
  2342. X        xexit(1);
  2343. X    }
  2344. X    if (CheckIO(&Iosr)) {
  2345. X        WaitIO(&Iosr);
  2346. X        AbortIO(&Iot0);
  2347. X        WaitIO(&Iot0);
  2348. X
  2349. X        ch = (int)XInBuf[0];
  2350. X
  2351. X        if (debug > 8) {
  2352. X        if (debugRead == 0)
  2353. X            printf("\nREAD ");
  2354. X        debugRead = 1;
  2355. X        printf("(waitc%d)", Iosr.IOSer.io_Actual);
  2356. X        printc((unsigned char)ch);
  2357. X        }
  2358. X        return(ch);
  2359. X    }
  2360. X    if (CheckIO(&Iot0)) {
  2361. X        WaitIO(&Iot0);
  2362. X
  2363. X        Iot0.tr_time.tv_secs = 3;
  2364. X        Iot0.tr_time.tv_micro= 0;
  2365. X
  2366. X        bytetimeout -= Iot0.tr_time.tv_secs;
  2367. X        if (bytetimeout > 0) {
  2368. X        if (CheckCarrier() == 0) {
  2369. X            AbortIO(&Iosr);
  2370. X            WaitIO(&Iosr);
  2371. X            break;
  2372. X        }
  2373. X        SendIO(&Iot0);
  2374. X        } else {
  2375. X        AbortIO(&Iosr);
  2376. X        WaitIO(&Iosr);
  2377. X        if (Iosr.IOSer.io_Actual == 1)
  2378. X            return((int)XInBuf[0]);
  2379. X        break;
  2380. X        }
  2381. X    }
  2382. X    }
  2383. X    if (debug > 8)
  2384. X    printf("\nRecv-EOF\n");
  2385. X    return(EOF);
  2386. X}
  2387. X
  2388. Xint
  2389. Xxwrite(buf, ctr)
  2390. Xconst void *buf;
  2391. Xint ctr;
  2392. X{
  2393. X    return(xxwrite(buf, ctr, 0));
  2394. X}
  2395. X
  2396. Xint
  2397. Xxwritea(buf, ctr)
  2398. Xconst void *buf;
  2399. Xint ctr;
  2400. X{
  2401. X    xxwrite(buf, ctr, 1);
  2402. X    return(ctr);
  2403. X}
  2404. X
  2405. Xint
  2406. Xxxwrite(buf, ctr, async)
  2407. Xconst void *buf;
  2408. Xint ctr;
  2409. Xint async;
  2410. X{
  2411. X    if (debug > 8) {
  2412. X    short i;
  2413. X    if (debugRead)
  2414. X        printf("\nWRITE ");
  2415. X    debugRead = 0;
  2416. X    for (i = 0; i < ctr; ++i) {
  2417. X        printc(((unsigned char *)buf)[i]);
  2418. X    }
  2419. X    printf("\n");
  2420. X    }
  2421. X    if (IoswIP) {
  2422. X    WaitIO(&Iosw);
  2423. X    IoswIP = 0;
  2424. X    }
  2425. X
  2426. X    Iosw.IOSer.io_Command = CMD_WRITE;
  2427. X    Iosw.IOSer.io_Length = ctr;
  2428. X    Iosw.IOSer.io_Data = (APTR)buf;
  2429. X    if (async) {
  2430. X    SendIO(&Iosw);
  2431. X    IoswIP = 1;
  2432. X    } else {
  2433. X    DoIO(&Iosw);
  2434. X    }
  2435. X    return ctr;
  2436. X}
  2437. X
  2438. Xvoid
  2439. XSendBreak()
  2440. X{
  2441. X    Ioss.IOSer.io_Command = SDCMD_BREAK;
  2442. X    DoIO(&Ioss);
  2443. X}
  2444. X
  2445. Xint
  2446. XCheckCarrier()
  2447. X{
  2448. X    Ioss.IOSer.io_Command = SDCMD_QUERY;
  2449. X    DoIO(&Ioss);
  2450. X    if (IgnoreCD)
  2451. X    return(1);
  2452. X    if (Ioss.io_Status & CIAF_COMCD)    /*  non-zero == no carrier */
  2453. X    return(0);
  2454. X    return(1);
  2455. X}
  2456. X
  2457. Xvoid *
  2458. Xbzero(s, cnt)
  2459. Xvoid   *s;
  2460. Xlong   cnt;
  2461. X{
  2462. X    setmem(s, cnt, 0);
  2463. X    return(s);
  2464. X}
  2465. X
  2466. Xvoid *
  2467. Xbcopy(from, to, cnt)
  2468. Xconst void   *from;
  2469. Xvoid   *to;
  2470. Xlong   cnt;
  2471. X{
  2472. X    movmem(from, to, cnt);
  2473. X    return(to);
  2474. X}
  2475. X
  2476. X/*
  2477. X * Transform a filename from a uucp packet (in Unix format) into a local
  2478. X * filename that will work in the local file system.
  2479. X */
  2480. X
  2481. Xvoid
  2482. Xmunge_filename(s, d)
  2483. Xchar *s, *d;
  2484. X{
  2485. X    if (*s != '~') {
  2486. X    if (s != d)
  2487. X        strcpy(d, s);
  2488. X    return;
  2489. X    }
  2490. X
  2491. X    /*
  2492. X     *    ~/ ...    convert to UUPUB:
  2493. X     *    ~user/...   convert to <homedir>/...
  2494. X     */
  2495. X
  2496. X    {
  2497. X    short i;
  2498. X    short c;
  2499. X    char *t;
  2500. X    struct passwd *pw;
  2501. X
  2502. X    for (i = 1; s[i] && s[i] != '/'; ++i);
  2503. X    c = s[i];
  2504. X
  2505. X    s[i] = 0;
  2506. X    if (i == 1)
  2507. X        pw = NULL;
  2508. X    else
  2509. X        pw = getpwnam(s + 1);
  2510. X    s[i] = c;
  2511. X
  2512. X    if (c == '/')
  2513. X        ++i;
  2514. X
  2515. X    if (pw) {
  2516. X        t = malloc(strlen(pw->pw_dir) + strlen(s + i) + 1);
  2517. X        strcpy(t, pw->pw_dir);
  2518. X    } else {
  2519. X        t = malloc(strlen(s + i) + 32);
  2520. X        strcpy(t, GetConfigDir(UUPUB));
  2521. X    }
  2522. X    strcat(t, s + i);
  2523. X    strcpy(d, t);
  2524. X    free(t);
  2525. X    }
  2526. X}
  2527. X
  2528. Xint
  2529. Xhangup()
  2530. X{
  2531. X    static char buf[128];
  2532. X
  2533. X    reset_modem();
  2534. X
  2535. X    sprintf(buf, "run >nil: <nil: %s", GetConfigProgram(UUXQT));
  2536. X
  2537. X    if (Execute(buf, NULL, NULL) == 0)
  2538. X    puts("Unable to run UUXQT");
  2539. X    return SUCCESS;
  2540. X}
  2541. X
  2542. Xstatic char names[MAXFILES*16];
  2543. Xstatic char *pointers[MAXFILES];
  2544. Xstatic int file_pointer;
  2545. X
  2546. Xchar *
  2547. Xwork_scan(system_name)
  2548. Xchar *system_name;
  2549. X{
  2550. X    static char name[128];
  2551. X    int count;
  2552. X
  2553. X    file_pointer = 0;
  2554. X
  2555. X    if (strlen(system_name) > 7) {
  2556. X    system_name[7] = '\0';
  2557. X    }
  2558. X
  2559. X    sprintf(name, "%sC.%s#?", MakeConfigPath(UUSPOOL, ""), system_name);
  2560. X
  2561. X    if (debug > 2)
  2562. X    printf("Looking for %s\n",name);
  2563. X
  2564. X    count = getfnl(name,names,sizeof(names),0);
  2565. X
  2566. X    if (count > 0) {
  2567. X    if (strbpl(pointers,MAXFILES,names) != count) {
  2568. X        printf("Too many command files for %s.\n",system_name);
  2569. X        return (char *)NULL;
  2570. X    }
  2571. X    } else {
  2572. X    return (char *)NULL;
  2573. X    }
  2574. X    if (debug > 2)
  2575. X    printf("Found -> %s\n", pointers[file_pointer]);
  2576. X    return (char *)1;
  2577. X}
  2578. X
  2579. Xchar *
  2580. Xwork_next()
  2581. X{
  2582. X    if (debug > 2)
  2583. X    printf("Found -> %s\n", pointers[file_pointer]);
  2584. X    return pointers[file_pointer++];
  2585. X}
  2586. X
  2587. X/*
  2588. X *  Closing and openning the serial device drops DTR
  2589. X */
  2590. X
  2591. Xvoid
  2592. Xamiga_closeopen(str)
  2593. Xchar *str;
  2594. X{
  2595. X    CloseSerial();
  2596. X    Delay(60);
  2597. X    OpenSerial();
  2598. X}
  2599. X
  2600. Xvoid
  2601. Xamiga_setup()
  2602. X{
  2603. X    mountrequest(0);        /*  disallow requesters */
  2604. X
  2605. X    OpenSerial();
  2606. X
  2607. X    if (OpenDevice(TIMERNAME, UNIT_VBLANK, &Iot0, 0))  {
  2608. X    Iot0.tr_node.io_Device = NULL;
  2609. X    printf("Can't open timer device.");
  2610. X    xexit(1);
  2611. X    }
  2612. X
  2613. X    Iot0.tr_node.io_Message.mn_ReplyPort = (struct MsgPort *)CreatePort("UUCICO-Timer", 0L);
  2614. X    Iot0.tr_node.io_Command = TR_ADDREQUEST;
  2615. X    Iot0.tr_node.io_Error = 0;
  2616. X
  2617. X    {
  2618. X    struct Task *task = (struct Task *)FindTask(NULL);
  2619. X    OldTaskName = task->tc_Node.ln_Name;
  2620. X    task->tc_Node.ln_Name = "uucico";
  2621. X    }
  2622. X}
  2623. X
  2624. Xvoid
  2625. Xset_baud(baud)
  2626. Xint baud;
  2627. X{
  2628. X    Iosr.IOSer.io_Command = SDCMD_SETPARAMS;
  2629. X    Iosr.io_SerFlags =    SERF_SHARED | SERF_XDISABLED;
  2630. X    Iosr.io_Baud = baud;
  2631. X    Iosr.io_ReadLen = 8L;
  2632. X    Iosr.io_WriteLen = 8L;
  2633. X    Iosr.io_CtlChar = 0x11130000L;
  2634. X    Iosr.io_RBufLen = 4096;
  2635. X
  2636. X    if (SevenWire)
  2637. X    Iosr.io_SerFlags |= SERF_7WIRE;
  2638. X
  2639. X    DoIO(&Iosr);
  2640. X}
  2641. X
  2642. Xvoid
  2643. XOpenSerial()
  2644. X{
  2645. X    Iosr.io_SerFlags = SERF_SHARED | SERF_XDISABLED;
  2646. X    Iosr.IOSer.io_Message.mn_ReplyPort = (struct MsgPort *)CreatePort("Read_RS",0);
  2647. X
  2648. X    if (SevenWire)
  2649. X    Iosr.io_SerFlags |= SERF_7WIRE;
  2650. X
  2651. X    if (OpenDevice(DeviceName, DeviceUnit, &Iosr, NULL)) {
  2652. X    Iosr.IOSer.io_Device = NULL;
  2653. X    printf("Can not open serial port for read.\n");
  2654. X    xexit(TRUE);
  2655. X    }
  2656. X
  2657. X    /*
  2658. X     *    Assume a Getty is running, if the opencount is > 2 then
  2659. X     *    assume collision and disallow
  2660. X     */
  2661. X
  2662. X    if (Iosr.IOSer.io_Device->dd_Library.lib_OpenCnt > 2) {
  2663. X    CloseDevice(&Iosr);
  2664. X    Iosr.IOSer.io_Device = NULL;
  2665. X    printf("Collision, serial port in use!\n");
  2666. X    xexit(TRUE);
  2667. X    }
  2668. X
  2669. X    /*
  2670. X     *    The public port 'Lock-<spname>-<unit>' is used to lock the
  2671. X     *    serial port (Getty will lock it this way while it is
  2672. X     *    receiving an incomming call so if we are Getty assume it
  2673. X     *    is already locked)
  2674. X     */
  2675. X
  2676. X    if (Getty == 0)
  2677. X    LockSerialPort(DeviceName, DeviceUnit);
  2678. X
  2679. X    Iosw = Iosr;
  2680. X    Iosw.IOSer.io_Message.mn_ReplyPort = (struct MsgPort *)CreatePort("Write_RS", 0);
  2681. X    Ioss = Iosw;
  2682. X
  2683. X    Iosr.IOSer.io_Command = SDCMD_QUERY;
  2684. X    DoIO(&Iosr);
  2685. X
  2686. X    set_baud(Iosr.io_Baud);
  2687. X}
  2688. X
  2689. Xvoid
  2690. XCloseSerial()
  2691. X{
  2692. X    if (IoswIP) {
  2693. X    WaitIO(&Iosw);
  2694. X    IoswIP = 0;
  2695. X    }
  2696. X    if (Iosr.IOSer.io_Device) {
  2697. X    CloseDevice(&Iosr);
  2698. X    Iosr.IOSer.io_Device = NULL;
  2699. X    if (Getty == 0)
  2700. X        UnLockSerialPort(DeviceName, DeviceUnit);
  2701. X    }
  2702. X    if (Iosr.IOSer.io_Message.mn_ReplyPort) {
  2703. X    DeletePort(Iosr.IOSer.io_Message.mn_ReplyPort);
  2704. X    Iosr.IOSer.io_Message.mn_ReplyPort = NULL;
  2705. X    }
  2706. X    if (Iosw.IOSer.io_Message.mn_ReplyPort) {
  2707. X    DeletePort(Iosw.IOSer.io_Message.mn_ReplyPort);
  2708. X    Iosw.IOSer.io_Message.mn_ReplyPort = NULL;
  2709. X    }
  2710. X}
  2711. X
  2712. Xvoid
  2713. Xxexit(code)
  2714. Xint code;
  2715. X{
  2716. X    ++InExitRoutine;
  2717. X
  2718. X    if (InExitRoutine == 1 && code && Iosr.IOSer.io_Device && CheckCarrier())
  2719. X    reset_modem();
  2720. X
  2721. X    CloseSerial();
  2722. X
  2723. X    {
  2724. X    struct Task *task = (struct Task *)FindTask(NULL);
  2725. X    if (OldTaskName)
  2726. X        task->tc_Node.ln_Name = OldTaskName;
  2727. X    }
  2728. X
  2729. X    if (Iot0.tr_node.io_Device) {
  2730. X    CloseDevice(&Iot0);
  2731. X    Iot0.tr_node.io_Device = NULL;
  2732. X    }
  2733. X    if (Iot0.tr_node.io_Message.mn_ReplyPort) {
  2734. X    DeletePort(Iot0.tr_node.io_Message.mn_ReplyPort);
  2735. X    Iot0.tr_node.io_Message.mn_ReplyPort = NULL;
  2736. X    }
  2737. X    chdir(path);
  2738. X    if (code)
  2739. X    printf("\nAbnormal Termination.\n");
  2740. X
  2741. X    mountrequest(1);
  2742. X
  2743. X    UnLockFiles();      /*  unlock any hanging locks */
  2744. X
  2745. X    exit(code);
  2746. X}
  2747. X
  2748. Xvoid
  2749. Xprintc(c)
  2750. Xunsigned char c;
  2751. X{
  2752. X    c &= 0x7F;
  2753. X
  2754. X    if (c < 32)
  2755. X    printf("^%c", c | 0x40);
  2756. X    else if (c == 32)
  2757. X    printf("_");
  2758. X    else if (c < 128)
  2759. X    printf("%c", c);
  2760. X    else
  2761. X    printf("(%02x)", c);
  2762. X}
  2763. X
  2764. END_OF_FILE
  2765. if test 11990 -ne `wc -c <'uucp2/src/uucico/sysdep.c'`; then
  2766.     echo shar: \"'uucp2/src/uucico/sysdep.c'\" unpacked with wrong size!
  2767. fi
  2768. # end of 'uucp2/src/uucico/sysdep.c'
  2769. fi
  2770. echo shar: End of archive 6 \(of 12\).
  2771. cp /dev/null ark6isdone
  2772. MISSING=""
  2773. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  2774.     if test ! -f ark${I}isdone ; then
  2775.     MISSING="${MISSING} ${I}"
  2776.     fi
  2777. done
  2778. if test "${MISSING}" = "" ; then
  2779.     echo You have unpacked all 12 archives.
  2780.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2781. else
  2782.     echo You still need to unpack the following archives:
  2783.     echo "        " ${MISSING}
  2784. fi
  2785. ##  End of shell archive.
  2786. exit 0
  2787. -- 
  2788. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  2789. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  2790. Post requests for sources, and general discussion to comp.sys.amiga.
  2791.